package com.ruoyi.tester.controller;

import java.util.List;

import com.ruoyi.tester.domain.TaskCallLogOut;
import com.ruoyi.tester.service.ITesterExecutorService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tester.domain.TesterTaskCallLog;
import com.ruoyi.tester.service.ITesterTaskCallLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务调用日志Controller
 *
 * @author SJ
 * @date 2022-04-26
 */
@Controller
@RequestMapping("/tester/task_call_log")
public class TesterTaskCallLogController extends BaseController
{
    private String prefix = "tester/task_call_log";

    @Autowired
    private ITesterTaskCallLogService testerTaskCallLogService;
    @Autowired
    private ITesterExecutorService testerExecutorService;

    @RequiresPermissions("tester:task_call_log:view")
    @GetMapping()
    public String task_call_log()
    {
        return prefix + "/task_call_log";
    }

    /**
     * 查询任务调用日志列表
     */
    @ApiOperation("查询任务调用日志列表")
    @RequiresPermissions("tester:task_call_log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TesterTaskCallLog testerTaskCallLog)
    {
        startPage();
        List<TaskCallLogOut> list = testerExecutorService.getTaskLog();
        return getDataTable(list);
    }

    /**
     * 导出任务调用日志列表
     */
    @RequiresPermissions("tester:task_call_log:export")
    @Log(title = "任务调用日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TesterTaskCallLog testerTaskCallLog)
    {
        List<TesterTaskCallLog> list = testerTaskCallLogService.selectTesterTaskCallLogList(testerTaskCallLog);
        ExcelUtil<TesterTaskCallLog> util = new ExcelUtil<TesterTaskCallLog>(TesterTaskCallLog.class);
        return util.exportExcel(list, "任务调用日志数据");
    }


    /**
     * 查看调用日志明细
     */
    @RequiresPermissions("tester:task_call_log:edit")
    @GetMapping("/edit/{taskCallLogId}")
    public String edit(@PathVariable("taskCallLogId") Long taskCallLogId, ModelMap mmap)
    {
        TesterTaskCallLog testerTaskCallLog = testerTaskCallLogService.selectTesterTaskCallLogByTaskCallLogId(taskCallLogId, null, null);
        mmap.put("testerTaskCallLog", testerTaskCallLog);
        return prefix + "/edit";
    }

    //过滤调用日志明细
    @GetMapping("/search")
    @ResponseBody
    public AjaxResult search(@RequestParam Long taskCallLogId, @RequestParam(required = false) String interfaceDesc,  @RequestParam(required = false) String status){
        TesterTaskCallLog testerTaskCallLog = testerTaskCallLogService.selectTesterTaskCallLogByTaskCallLogId(taskCallLogId, interfaceDesc, status);
        return success(testerTaskCallLog);
    }

    /**
     * 删除任务调用日志
     */
    @ApiOperation("删除任务调用日志")
    @RequiresPermissions("tester:task_call_log:remove")
    @Log(title = "任务调用日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(testerTaskCallLogService.deleteTesterTaskCallLogByTaskCallLogIds(ids));
    }
}
